package structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 字典类型
 * @Author: lxt
 * @CreateDate: 2019/11/1
 **/
public class DirectoryInfo extends AbstractDirectory {
    private List<AbstractDirectory> directories;

    public DirectoryInfo(String name) {
        super.setName(name);
        directories = new ArrayList<AbstractDirectory>();
    }

    public void add(AbstractDirectory directory) {
        directories.add(directory);
    }

    @Override
    public String getValue() {
        return this.getValue();
    }

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("字典类型 [").append(this.getName()).append("] 的字典值有：\n");

        for (AbstractDirectory directory : directories) {
            if (directory instanceof DirectoryInfo) {
                buffer.append("\t").append(directory.toString());
            } else {
                buffer.append("\tname：").append(directory.getName()).append("\t value：").append(directory.getValue()).append("\n");
            }
        }

        return buffer.toString();
    }
}
